/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaclientcp3110.View.Component;

import javaclientcp3110.Model.Component.CompAddModel;
import common.Objects.Category;
import javaclientcp3110.Model.MainModel;
import common.UCM.UC2AL;
import javaclientcp3110.UCM.UCAddComponent;
import javax.swing.JOptionPane;

/*
 * LoginPanelView.java
 *
 * Created on 14/08/2009, 3:26:48 PM
 * View created through generator. This is the view for the add view.
 * @author Richard Irons
 */
public class CompAddView extends javax.swing.JPanel {
    private CompAddModel model;
    /** Creates new form LoginPanelView */
    public CompAddView() {
        this(new CompAddModel());
    }
    /**
     * Constructor to set the model to the input
     * @param model
     */
    public CompAddView(CompAddModel model) {
        this.model = model;
        initComponents();
        compAddButton.addActionListener(new UC2AL(new UCAddComponent(this, model)));

        compCatagoryComboBox.updateView(MainModel.getInstance().getCategorys());
    }
    public void clearFields() {
        compNameTextField.setText("");
        compDescriptionTextField.setText("");
        compStockTextField.setText("");
        compPriceTextField.setText("");
    }
    public void errorMessage(String message) {
        JOptionPane.showMessageDialog(null,
            message,
            "Error",
            JOptionPane.ERROR_MESSAGE);
    }
    public void successMessage(String message) {
        JOptionPane.showMessageDialog(null,
            message,
            "Success!",
            JOptionPane.INFORMATION_MESSAGE);
    }

    public String getCompName(){return compNameTextField.getText();}
    public String getCompDescription(){return compDescriptionTextField.getText();}
    public int getCompCurrentStock(){return Integer.parseInt(compStockTextField.getText());}
    public double getCompPrice(){return Double.parseDouble(compPriceTextField.getText());}
    public Category getCompCategory(){return (Category) compCatagoryComboBox.getSelectedItem();}

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        compNameLable = new javax.swing.JLabel();
        compDescriptionLabel = new javax.swing.JLabel();
        compStockLabel = new javax.swing.JLabel();
        compPriceLabel = new javax.swing.JLabel();
        compNameTextField = new javax.swing.JTextField();
        compDescriptionTextField = new javax.swing.JTextField();
        compStockTextField = new javax.swing.JTextField();
        compPriceTextField = new javax.swing.JTextField();
        titleLabel = new javax.swing.JLabel();
        compAddButton = new javax.swing.JButton();
        compCatagoryLabel = new javax.swing.JLabel();
        compCatagoryComboBox = new javaclientcp3110.View.Component.CategoryListView();

        setMaximumSize(new java.awt.Dimension(500, 380));
        setMinimumSize(new java.awt.Dimension(500, 380));
        setPreferredSize(new java.awt.Dimension(500, 380));

        compNameLable.setText("Name:");

        compDescriptionLabel.setText("Description:");

        compStockLabel.setText("Current Stock:");

        compPriceLabel.setText("Price:");

        compNameTextField.setColumns(25);
        compNameTextField.setMaximumSize(new java.awt.Dimension(6, 20));

        compDescriptionTextField.setColumns(25);
        compDescriptionTextField.setMaximumSize(new java.awt.Dimension(6, 20));

        compStockTextField.setColumns(25);
        compStockTextField.setMaximumSize(new java.awt.Dimension(6, 20));

        compPriceTextField.setColumns(25);
        compPriceTextField.setMaximumSize(new java.awt.Dimension(6, 20));

        titleLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        titleLabel.setText("Enter the details of the new component.");

        compAddButton.setText("Add Component");

        compCatagoryLabel.setText("Catagory:");

        compCatagoryComboBox.setMaximumSize(new java.awt.Dimension(28, 20));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(101, 101, 101)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(compAddButton)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addGap(21, 21, 21)
                            .addComponent(compCatagoryLabel)
                            .addGap(18, 18, 18)
                            .addComponent(compCatagoryComboBox, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(titleLabel)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(compNameLable)
                                    .addComponent(compStockLabel)
                                    .addComponent(compPriceLabel)
                                    .addComponent(compDescriptionLabel))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(compPriceTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(compStockTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(compDescriptionTextField, 0, 0, Short.MAX_VALUE)
                                    .addComponent(compNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE))))))
                .addGap(123, 123, 123))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addComponent(titleLabel)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(compNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(compNameLable))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(compDescriptionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(compDescriptionLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(compStockTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(compStockLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(compPriceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(compPriceLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(compCatagoryLabel)
                    .addComponent(compCatagoryComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(compAddButton)
                .addContainerGap(143, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton compAddButton;
    private javaclientcp3110.View.Component.CategoryListView compCatagoryComboBox;
    private javax.swing.JLabel compCatagoryLabel;
    private javax.swing.JLabel compDescriptionLabel;
    private javax.swing.JTextField compDescriptionTextField;
    private javax.swing.JLabel compNameLable;
    private javax.swing.JTextField compNameTextField;
    private javax.swing.JLabel compPriceLabel;
    private javax.swing.JTextField compPriceTextField;
    private javax.swing.JLabel compStockLabel;
    private javax.swing.JTextField compStockTextField;
    private javax.swing.JLabel titleLabel;
    // End of variables declaration//GEN-END:variables

}
